import pandas as pd



df = pd.read_csv('/Users/yibo/PycharmProjects/lagou/homework14/Wholesale customers data.csv')
print(df)


print(df.info())


print(df.describe())

from sklearn.preprocessing import Normalizer

normalizer = Normalizer().fit(df)

normalized_data = normalizer.transform(df)

print(normalized_data)

from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score #轮廓系数
from matplotlib import pyplot as plt


score=[]
for i in range(2,100):
    cluster = KMeans(n_clusters=i,random_state=0).fit(df)
    score.append(silhouette_score(df,cluster.labels_))


print(score)

plt.plot(range(2,100),score)

plt.show()

cluster = KMeans(n_clusters=3,random_state=0).fit(df)

print(cluster.cluster_centers_)

df['label'] = cluster.labels_
sizes = df.groupby(by='label').count()


plt.pie(sizes['Channel'],labels=sizes.index)
plt.show()

